package sourceagile.webservices;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jettison.json.JSONArray;

import sourceagile.server.classRepositories.subversionFileRepository.ListRepositoryFiles;

@SuppressWarnings("serial")
public class ListFilesServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException {

		String repositoryURL = request.getParameter("repositoryURL");

		repositoryURL = repositoryURL.replaceAll("-", "/");

		String username = request.getParameter("username");

		String password = request.getParameter("password");

		JSONArray list = ListRepositoryFiles.listEntries(repositoryURL,
				username, password);

		String answer = Utilities.getCallback(request.getParameter("callback"),
				list.toString());

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}
}
